package health.lm.com.order.adapter;

import android.support.annotation.Nullable;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import health.lm.com.component_base.widget.RatingBar;
import health.lm.com.order.R;
import health.lm.com.order.entity.RecordListEntity;

/**
 * 消费记录
 * @author Administrator
 */

public class RecordListAdapter extends BaseQuickAdapter<RecordListEntity.Lists,BaseViewHolder> {
    private String id;
    public RecordListAdapter(@Nullable List<RecordListEntity.Lists> data,String id) {
        super(R.layout.item_record_lists, data);
        this.id = id;
    }

    @Override
    protected void convert(BaseViewHolder helper, RecordListEntity.Lists item) {
        helper.setText(R.id.tv_record_id1,String.format("订单号:%s",item.getOrderid()))
                .setText(R.id.tv_record_date,getDate2String(item.getCreate_time(),"yyyy-MM-dd HH:mm:ss"))
                .setText(R.id.tv_record_shop_name,item.getUnion_name())
                .setText(R.id.tv_record_pay_money,String.format("￥%s",item.getMoney()))
                .setText(R.id.tv_record_h_money,item.getCoin())
                .setText(R.id.tv_record_content,item.getContent())
                .setGone(R.id.tv_record_go_pj, StringUtils.equals("1",id))
                .setGone(R.id.ll_content,!StringUtils.equals("1",id))
                .addOnClickListener(R.id.tv_record_go_pj);
        ((RatingBar)helper.getView(R.id.rb_record_start)).setStar(item.getStar());
    }
    /**
     *
     * @param time  1541569323155
     * @param pattern yyyy-MM-dd HH:mm:ss
     * @return 2018-11-07 13:42:03
     */
    public static String getDate2String(long time, String pattern) {
        Date date = new Date(time*1000L);
        SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.getDefault());
        return format.format(date);
    }
}
